<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<!--User: xulf Date: 2018/11/9 Time: 10:12-->
<link th:href="@{/css/labelColor.css}" rel="stylesheet">
<body>
<form id="changeForm" role="form" method="post" action="change/add">
    <div class="form-group">
        <label for="changeNo">变更单号<span>*</span></label>
        <input class="form-control" id="changeNo" name="changeNo" type="text"
               placeholder="请输入变更单号"/>
    </div>
    <div class="form-group">
        <label for="createTime">创建时间</label>
        <input class="form-control" id="createTime" name="createTime" type="text"
        disabled="disabled"       placeholder="请输入创建时间"/>
    </div>
    <div class="form-group">
        <label for="originTime">流程发起时间</label>
        <input class="form-control" id="originTime" name="originTime" type="text"
        disabled="disabled"       placeholder="请输入流程发起时间"/>
    </div>
    <div class="form-group">
        <label for="deptName">部门</label>
        <input class="form-control" id="deptName" name="deptName" type="text"
        disabled="disabled"       placeholder="请输入部门"/>
    </div>
    <div class="form-group">
        <label for="originator">发起人</label>
        <input class="form-control" id="originator" name="originator" type="text"
        disabled="disabled"       placeholder="请输入发起人"/>
    </div>
    <div class="form-group">
        <label for="createName">表单创建者</label>
        <input class="form-control" id="createName" name="createName" type="text"
        disabled="disabled"       placeholder="请输入表单创建者"/>
    </div>
    <div class="form-group">
        <label for="tel">联系电话</label>
        <input class="form-control" id="tel" name="tel" type="text"
               placeholder="请输入联系电话"/>
    </div>
    <div class="form-group">
        <label for="state">变更单状态<span>*</span></label>
        <select class="form-control" name="state" id="state"disabled="disabled" placeholder="请选择变更单状态">
            <!--<option>进行中</option>-->
            <!--<option>完成</option>-->
            <!--<option>取消</option>-->
            <option>进行中</option>
            <option>流程中</option>
            <option>已完成</option>
        </select>
    </div>
    <div class="form-group">
        <label for="changeType">变更类型</label>
        <input class="form-control" id="changeType" name="changeType" type="text"
        placeholder="请输入变更类型"/>
    </div>
    <div class="form-group">
        <label for="relationChangeNo">是否关联变更</label>
        <input class="form-control" id="relationChangeNo" name="relationChangeNo" type="text"
               placeholder="请输入关联变更号"/>
    </div>
    <div class="form-group">
        <label for="marketType">上市类型</label>
        <select class="form-control" name="marketType" id="marketType" placeholder="请选择上市类型">
            <option>上市前</option>
            <option>上市后</option>
        </select>
    </div>
    <div class="form-group">
        <label for="projectStage">项目所属阶段</label>
        <input class="form-control" id="projectStage" name="projectStage" type="text"
               placeholder="请输入项目所属阶段"/>
    </div>
    <div class="form-group">
        <label for="remark">备注</label>
        <input class="form-control" id="remark" name="remark" type="text"
               placeholder="请输入备注"/>
    </div>
</form>
<script th:inline="javascript">
    <![CDATA[
    $(function () {
        $('#changeForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                changeNo: {
                    message: '变更单号验证失败',
                    validators: {
                        notEmpty: {
                            message: '变更单号不能为空'
                        },
                        stringLength: {
                            min: 12,
                            max: 12,
                            message: '变更单号长度必须是12位'
                        },
                        threshold: 12,
                        remote: {//ajax验证。server result:{"valid",true or false} 向服务发送当前input name值，获得一个json数据。例表示正确：{"valid",true}
                            url: "change/exist",//验证地址
                            data: function (validator) {// 获取需要传送到后台的验证的数据
                                return {
                                    changeNo: $('#changeNo').val()
                                }
                            },
                            message: '变更单号已存在',//提示消息
                            // delay :  500,
                            type: 'POST'//请求方式，
                        },
                    }

                }
            }
        });
        // 绑定dialog的确定按钮的监听事件
        $("#btnOk", window.top.document).click(function () {
            var bootstrapValidator = $("#changeForm", window.top.document).data('bootstrapValidator');
            bootstrapValidator.validate();
            if (bootstrapValidator.isValid()) {
                var url = $("#changeForm", window.top.document).attr('action');
                // var projectId= $("#project", window.top.document).val();
                var myData = JSON.stringify({
                    "changeNo": $("#changeNo").val(),
                    // "createTime":$("#createTime").val(),
                    // "originTime":$("#originTime").val(),
                    // "deptName":$("#deptName").val(),
                    // "originator":$("#originator").val(),
                    // "createName":$("#createName").val(),
                    "tel": $("#tel").val(),
                    "state": $("#state").val(),
                    "changeType": $("#changeType").val(),
                    "relationChangeNo": $("#relationChangeNo").val(),
                    "marketType": $("#marketType").val(),
                    "projectStage": $("#projectStage").val(),
                    "remark": $("#remark").val(),

                    "projectId": $("#project", window.top.document).val(),
                });

                $.ajax({
                    contentType:
                        "application/json",
                    type:
                        'POST',
                    url: url,
                    data: myData,
                    success:
                        function (result) {
                            // $('.modal-dialog', window.top.document).parent('div').remove()
                            // $('body', window.top.document).find('.modal-backdrop').remove();
                            // jquery 调用刷新当前操作的table页面的refresh方法
                            // $(window.parent.document).contents().find(".tab-pane.fade.active.in iframe")[0].contentWindow.doQuery();
                            activeTabBodyRefresh();
                            /*if (result)
                                window.Ewin.alert({message: '修改数据成功!'});
                            else
                                window.Ewin.alert({message: '修改数据失败!'});*/
                            // window.Ewin.alert({message:result.errMsg});
                            if (result.success) {
                                layer.msg('添加成功', {icon: 1, time: 2000})
                            }
                            else if (!result.success) {
                                window.Ewin.alert({message: result.errMsg})
                            }
                        },
                    error: function (status) {
                        window.Ewin.alert({message: status.status + ':添加数据失败!'});
                    }
                });
            }
        });
    })
    $(document).keydown(function (event) {
        if (event.keyCode == 13) {
            $('form').each(function () {
                event.preventDefault();
            });
        }
    });
    // $("#changeNo").blur(function() {
    //     var changeNo = $("#changeNo").val();
    //     $.ajax({
    //         url:"change/exist?changeNo="+changeNo,
    //         success : function(result){
    //             if (!result.success){
    //                 window.Ewin.alert({message:'您输入的变更单号已存在'})
    //             }
    //         }
    //     })
    // })
    ]]>
</script>
<script th:src="@{/layer/layer.js}"></script>
<script th:src="@{/js/helper/dateFormater.js}"></script>
</body>
</html>